console.log(1)
var getData = {};
var FSAASCompary  //企业id
var codeurl ="/Ecp.Picture.viewQrCode.img?Url=" + escape(window.location.href)
var ua = parseUA();
    //跳到pc页面
if (!ua.mobile) {
    console.log("pc")
    // P_start()
    // P_AddAjax()
}else{
	(function (doc, win) {
    var docEl = doc.documentElement,
        resizeEvt = 'orientationchange' in window ? 'orientationchange' : 'resize',
        recalc = function () {
            var clientWidth = docEl.clientWidth;
            if (!clientWidth) return;
            if(clientWidth>=750){
                docEl.style.fontSize = '100px';
            }else{
                docEl.style.fontSize = 100 * (clientWidth / 750) + 'px';
            }
        };
    if (!doc.addEventListener) return;
    win.addEventListener(resizeEvt, recalc, false);
    doc.addEventListener('DOMContentLoaded', recalc, false);
})(document, window);
    console.log("手机")
    // addAjax()
    $("body").prepend('<div class="M"></div>')
}
// =====判断pc还是移动端=================================================================
function parseUA() {
    var u = navigator.userAgent;
    var u2 = navigator.userAgent.toLowerCase();
    return { //移动终端浏览器版本信息
        trident: u.indexOf('Trident') > -1, //IE内核
        presto: u.indexOf('Presto') > -1, //opera内核
        webKit: u.indexOf('AppleWebKit') > -1, //苹果、谷歌内核
        gecko: u.indexOf('Gecko') > -1 && u.indexOf('KHTML') == -1, //火狐内核
        mobile: !!u.match(/AppleWebKit.*Mobile.*/), //是否为移动终端
        ios: !!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/), //ios终端
        android: u.indexOf('Android') > -1 || u.indexOf('Linux') > -1, //android终端或uc浏览器
        iPhone: u.indexOf('iPhone') > -1, //是否为iPhone或者QQHD浏览器
        iPad: u.indexOf('iPad') > -1, //是否iPad
        webApp: u.indexOf('Safari') == -1, //是否web应该程序，没有头部与底部
        iosv: u.substr(u.indexOf('iPhone OS') + 9, 3),
        weixin: u2.match(/MicroMessenger/i) == "micromessenger",
        ali: u.indexOf('AliApp') > -1,
    };
}
//移动端请求数据；=======================================================================================
function addAjax(){
	configWeixin()
	var search =  window.location.search.split("?")[1]
	var EntityId = search.split("&")[0].split("=")[1];
    var args = JSON.stringify({args: {
      entityId:EntityId,
    }});
    $.ajax({
        type: 'POST',
        url: '/api/CUTC.TravelNotes.getTraveNotes.vdt',
        data: args,
        contentType: 'application/json;charset=UTF-8',
        success: function(data) {
        console.log(JSON.stringify(data))
		getData = data.data
		$("title").html(getData.cover.FItineraryCoverTitle)
		FSAASCompary = getData.defaultData.FSAASCompary//企业id
		M_basic_addHeader (getData)

		M_basic_addMain (getData)
		M_basic_addBottomImg()
		if(getData.defaultData.showLogin == "1"){
		  M_basic_addFooter (getData)
		}
		
		// 添加音乐链接   和 微信自动播放
		addMusicUrl(getData)
		document.addEventListener("WeixinJSBridgeReady",function(){
			document.getElementById('bgm').play()
		})
		
		//微分享数据整理
		var imgUrl = window.location.protocol + '//' + window.location.host + '/travelShare/images/error_cover.jpg'
		if (getData.cover.FCoverImage) {
			imgUrl = window.location.protocol + '//' + window.location.host + '/Ecp.Picture.view.img?pictureId=' + getData.FCoverImage;
		}
		var FItineraryCoverTitle = getData.cover.FItineraryCoverTitle
		var FProductFeatures = getData.cover.FProductFeatures
		if (getData.cover) {
			FItineraryCoverTitle = getData.cover.FItineraryCoverTitle
			FProductFeatures = getData.cover.FProductFeatures
			imgUrl = window.location.protocol + '//' + window.location.host + '/Ecp.Picture.view.img?pictureId=' + getData.cover.FCoverImage;
		}
		  
		
	}
	});
}

// ====移动端  方法====================================================================================================================================================================================
function addMusicUrl(getData){
	$("#M_basic_bgm").attr("src","/" + getData.defaultData.FBackgroundMusic)
}
$(document).on("touchstart",".M_basic_bgm-btn",function(e){

	var dom = document.getElementById('M_basic_bgm');
	if( dom.paused ){
		dom.play();
		$(".M_basic_bgm-btn").removeClass("M_basic_mut");
	}else{
		dom.pause();
		$(".M_basic_bgm-btn").addClass("M_basic_mut");
	}
});
$(document).on("touchstart",".M_basic_register_signupClick",function(){
    judge()
})
function judge(){
	var name = $(".M_basic_register_cell_name").val();
	var tel = $(".M_basic_register_cell_tel").val();
	var textarea = $(".M_basic_register_cellOther textarea").val();
	var email = $(".M_basic_register_cell_email").val();
	var EntityId =  window.location.search.split("?")[1].split("&")[0].split("=")[1]
	var args = JSON.stringify({args: {
	  travelNotesEntityId:EntityId,
	  FSAASCompary:FSAASCompary,
	  FName: name,
	  FPhone: tel,
	  FContext: textarea,
	  FWeChat: "",
	  FEmail: email
	}});
	if(name == "" || tel == ""){
	  $(".M_basic_warning").text("姓名、手机不能为空")
	  $(".M_basic_warning").addClass("M_basic_warning_error")
	  $(".M_basic_warning").addClass("M_basic_warningDown")
	  setTimeout(function(){
	    $(".M_basic_warning").removeClass("M_basic_warningDown")
	    $(".M_basic_warning").removeClass("M_basic_warning_error")
	  },3300)
	}else{
	  $.ajax({
	    type: 'POST',
	    url: '/api/CUTC.WillApply.apply.vdt',
	    data: args,
	    contentType: 'application/json;charset=UTF-8',
	    success: function(data) {
		  console.log(data)
	      $(".M_basic_warning").text("报名成功！！！")
	      $(".M_basic_warning").addClass("M_basic_warning_true")
	      $(".M_basic_warning").addClass("M_basic_warningDown")
	      setTimeout(function(){
	        $(".M_basic_warning").removeClass("M_basic_warningDown")
	        $(".M_basic_warning").removeClass("M_basic_warning_true")
	      },3300)
	      $(".M_basic_register_signup").text("报名成功")  
	      $(".M_basic_register_signup").removeClass("M_basic_register_signupClick")
	      $(".M_basic_register_signup").addClass("M_basic_register_signupGry") 
	    }
	  })
	}
}
function M_basic_addHeader (getData){
	$(".M").append(
	  '<div class="M_basic_warning">姓名、手机不能为空</div>'+
	  '<div class="M_basic_bgm-btn"></div>'+
	  '<audio id="M_basic_bgm" src="" autoplay  loop style="display: none; width: 0; height: 0;"></audio>'+
	  '<div class="M_basic_header">'+
	    '<img class="M_basic_header_img" src="/Ecp.Picture.view.img?pictureId='+ getData.cover.FCoverImage +'" />'+
	    '<div class="M_basic_header_box">'+
	      '<div class="M_basic_header_title">'+ getData.cover.FItineraryCoverTitle +'</div>'+
	    '</div>'+
	    '<img class="M_basic_header_bottom" src="images/M_basic_header_bottom.png" / />'+
	  '</div>'+
	  '<div class="M_basic_introduce"><pre>'+ getData.cover.FProductFeatures  +'</pre></div>'
	)
}

function M_basic_addMain (getData){
	for(var i  in getData.routeDesc){
		$(".M").append(
		  '<div class="M_basic_dayMain">'+
		    '<div class="M_basic_dayMain_left">'+
		    '</div>'+
		    '<div class="M_basic_dayMain_right">'+
		      '<div class="M_basic_dayMain_right_Day">Day' + (i*1 + 1) + '</div>'+
		      '<pre>'+ getData.routeDesc[i].FAdvancedEditingMode +'</pre>'+

		    '</div>'+
		  '</div>'
		)
	}
	
}
function M_basic_addBottomImg(){
	$(".M").append(
		'<img class="M_basic_Separate" src="images/M_basic_Separate.png" />'
	)
}
function M_basic_addFooter (){
	$(".M").append( 
	  '<div class="M_basic_registerBox">'+
	    '<div class="M_basic_register_cell register">'+
          '<div class="M_basic_register_cell_left">姓名:</div>'+
          '<input class="M_basic_register_cell_right M_basic_register_cell_name" placeholder="请输入姓名"  />'+
        '</div>'+
       '<div class="M_basic_register_cell">'+
          '<div class="M_basic_register_cell_left">电话:</div>'+
          '<input class="M_basic_register_cell_right M_basic_register_cell_tel" type="tel" placeholder="请输入电话"  />'+
        '</div>'+
        '<div class="M_basic_register_cell">'+
          '<div class="M_basic_register_cell_left">邮箱:</div>'+
          '<input class="M_basic_register_cell_right M_basic_register_cell_email" type="email" placeholder="请输入邮箱"  />'+
        '</div>'+
        '<div class="M_basic_register_cellOther">'+
          '<div class="M_basic_register_cell_left">备注:</div>'+
          '<textarea  rows="6" cols="30" placeholder="  请输入备注信息…" ></textarea>'+
        '</div>'+
        '<div class="M_basic_register_signup M_basic_register_signupClick">我要报名</div>'+
	  '</div>'
	)
}



